package com.ruoyi.web.controller.position;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.control.dto.RYJZDto;
import com.ruoyi.position.domain.Ryjz;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.position.domain.Ryqy;
import com.ruoyi.position.service.IRyqyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人员定位-区域Controller
 *
 * @author hcc
 * @date 2024-10-31
 */
@RestController
@RequestMapping("/control/ryqy")
public class RyqyController extends BaseController
{
    @Autowired
    private IRyqyService ryqyService;

    /**
     * 查询人员定位-区域列表
     */
    //@PreAuthorize("@ss.hasPermi('control:ryqy:list')")
    @GetMapping("/list")
    public TableDataInfo list(Ryqy ryqy)
    {
        startPage();
        List<Ryqy> list = ryqyService.selectRyqyList(ryqy);
        return getDataTable(list);
    }
    /**
     * 查询人员定位-区域列表
     */
    @PreAuthorize("@ss.hasPermi('control:ryqy:list')")
    @GetMapping("/listArr")
    public List<Ryqy> listArr(Ryqy ryqy)
    {
        List<Ryqy> list = ryqyService.selectRyqyList(ryqy).stream().map(item ->{
            List<Ryqy> ryqyList= ryqyService.selectRyqyNum(item);
            item.setVerifiedPersonNumber(Long.valueOf(ryqyList.size()));
            return item;
        }).collect(Collectors.toList());
        return list;
    }

    /**
     * 导出人员定位-区域列表
     */
    @PreAuthorize("@ss.hasPermi('control:ryqy:export')")
    @Log(title = "人员定位-区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Ryqy ryqy)
    {
        List<Ryqy> list = ryqyService.selectRyqyList(ryqy);
        ExcelUtil<Ryqy> util = new ExcelUtil<Ryqy>(Ryqy.class);
        util.exportExcel(response, list, "人员定位-区域数据");
    }

    /**
     * 获取人员定位-区域详细信息
     */
    @PreAuthorize("@ss.hasPermi('control:ryqy:query')")
    @GetMapping(value = "/{positionAreaId}")
    public AjaxResult getInfo(@PathVariable("positionAreaId") String positionAreaId)
    {
        return success(ryqyService.selectRyqyByPositionAreaId(positionAreaId));
    }

    /**
     * 新增人员定位-区域
     */
    @PreAuthorize("@ss.hasPermi('control:ryqy:add')")
    @Log(title = "人员定位-区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Ryqy ryqy)
    {
        return toAjax(ryqyService.insertRyqy(ryqy));
    }

    /**
     * 修改人员定位-区域
     */
    @PreAuthorize("@ss.hasPermi('control:ryqy:edit')")
    @Log(title = "人员定位-区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Ryqy ryqy)
    {
        return toAjax(ryqyService.updateRyqy(ryqy));
    }

    /**
     * 删除人员定位-区域
     */
    @PreAuthorize("@ss.hasPermi('control:ryqy:remove')")
    @Log(title = "人员定位-区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{positionAreaIds}")
    public AjaxResult remove(@PathVariable String[] positionAreaIds)
    {
        return toAjax(ryqyService.deleteRyqyByPositionAreaIds(positionAreaIds));
    }
}
